<!DOCTYPE html>

<html lang="zh-Hans">
  <head>
    <meta charset="utf-8" />
    <meta name="author" content="rogepi" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="/vue.global.js"></script>
    <title>3-event-number</title>
  </head>

  <body>
    <div id="event-number">
      <ul>
        <!-- 显示过滤/排序后的结果 -->
        <li v-for="n in evenNumbers">{{ n }}</li>
      </ul>
      <!-- 在计算属性不适用的情况下 (例如，在嵌套 v-for 循环中)
         可以使用一个方法： -->
      <ul v-for="numbers in sets">
        <li v-for="n in even(numbers)">{{ n }}</li>
      </ul>
    </div>
    <script>
      Vue.createApp({
        data() {
          return {
            numbers: [1, 2, 3, 4, 5],
            sets: [
              [1, 2, 3, 4, 5],
              [6, 7, 8, 9, 10],
            ],
          };
        },
        computed: {
          evenNumbers() {
            return this.numbers.filter((number) => number % 2 === 0);
          },
        },
        methods: {
          even(numbers) {
            return numbers.filter((number) => number % 2 === 0);
          },
        },
      }).mount('#event-number');
    </script>
  </body>
</html>
